package core

import (
	"gin_study_blog/common"
	"github.com/olivere/elastic/v7"
	"github.com/sirupsen/logrus"
)

// EsConnect es 封装
func EsConnect() *elastic.Client {
	var err error
	sniffOpt := elastic.SetSniff(false)

	c, err := elastic.NewClient(
		elastic.SetURL(common.Config.Es.Url()),
		sniffOpt,
		elastic.SetBasicAuth(common.Config.Es.Username, common.Config.Es.Password),
	)

	if err != nil {
		logrus.Errorf("es连接失败 %s", err.Error())
	}
	return c
}
